const Request=(method,url,data={},header={},useData1,useData2,context)=>{
  return new Promise((resolve,reject)=>{
     wx.showLoading({
       title: '加载中...',
     });
     const app=getApp();
     wx.request({
       url,
       method, 
       data, 
       header,    
       useData1,
       useData2,
       success: (res) => {
         resolve(res.data);
         if (res.data.code===600) {
            console.log("token过期或为空，重新登陆！");
            wx.showToast({
              title: 'token过期或为空，请重新登录！',
              icon: 'none', 
              duration: 2000
            });
            app.userLogin().then(()=>{
              makeRequest();
            })
         }else{
          console.log('请求成功：', res.data.msg+" "+res.data.code);  
          const arrayLength = res.data.data ? res.data.data.length : 0;
          if (context && typeof context.setData === 'function') {  
           context.setData({  
             [useData1]: res.data.data,  
             [useData2]: arrayLength  
           });  
         }     
         }
               
        },
       fail: (err) => {
         wx.showToast({
           title: '加载失败，请稍后再试',
           icon: 'none', 
           duration: 2000
         });
         reject(err)
       },
       complete:()=>{
        wx.hideLoading();
       }
      
     });
   })
}
module.exports={
  Request,
}